/* -----------------------------------------------------------------------------
 * PROJECT    : net.lwf
 * FILE       : InitializationServlet.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Dec 19, 2008       Raghu Sarraff			       Created
 */
package net.lwf.web.servlet;

import javax.servlet.http.HttpServlet;

import lwf.factory.WordImageFactory;
import net.lwf.common.constant.ICommonConstant;
import net.lwf.hibernate.dao.AppHitDAO;
import net.lwf.service.AppHitCounter;
import net.lwf.service.LwfService;

import org.apache.log4j.Logger;

/**
 * Type the class description here
 *  
 */
public class InitializationServlet extends HttpServlet {
	
	private static final Logger logger = Logger.getLogger(net.lwf.web.servlet.InitializationServlet.class);

	private static final long serialVersionUID = 1L;

	public void init() {
		String realpath = getServletContext().getRealPath(ICommonConstant.FORWARD_SLASH);
		String imagefolder = getInitParameter("imagefolder"); //configured in web.xml
		
		WordImageFactory.getInstance().setImageFolder(realpath + imagefolder);
		
		//Initialize Security
	/*	String transformation = LookupFactory.getInstance().getValue(IWebConstant.SECURITY_GROUP, IWebConstant.DES_ENCRYPTION_TRANSFORMATION_KEY);
		String algorithm = LookupFactory.getInstance().getValue(IWebConstant.SECURITY_GROUP, IWebConstant.DES_ALGORITHM_KEY);
		
		LwfSecurity.getInstance().init(transformation, algorithm);
		//LwfSecurity.getInstance().initBasicTextEncryptor(pwd);
		
		LwfSecurity.getInstance().initPasswordEncryptor();*/
		
		//Set Initial website visit count
		//this.setVisitorCount();
	}
	
	public void destroy() {
		if (!LwfService.isMock()) {
			logger.debug(".......... Writing the last hit counter value............");
			new AppHitDAO().logHit(AppHitCounter.counter);
		}
	}
	
	private void setVisitorCount() {
		if (!LwfService.isMock()) {
			AppHitCounter.counter = new AppHitDAO().getHitCounter();
		}
	}
	
	

} //InitializationServlet

